package cc.rengu.igas.share.common.util;


import cc.rengu.igas.share.common.interfaces.BeanTransferUtilCallBack;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

/**
 * @author wukefan
 * @version 1.0.0
 * @date 2020/6/24 18:15
 */
public class BeanTranferUtil extends BeanUtils {
    public static <S, T> List<T> copyListProperites(List<S> sources, Supplier<T> target) {
        return copyListProperites(sources, target, null);
    }

    private static <S, T> List<T> copyListProperites(List<S> sources, Supplier<T> target, BeanTransferUtilCallBack<S, T> callBack) {
        List<T> list = new ArrayList<>(sources.size());
        for (S source : sources) {
            T t = target.get();
            copyProperties(source, t);
            list.add(t);
            if (null != callBack) {
                callBack.callBack(source, t);
            }
        }
        return list;
    }


}
